import mysql.connector



sql = '''
select
    id,
	interface_para_code ,
	interface_para_name,
	interface_para_position,
	interface_para_type ,
	interface_data_type ,
	interface_para_default
from
	etl_interface_para
where
	interface_id = %s
'''
cnx = mysql.connector.connect(user='biadmin', password='vRt83wRYq7LV',
                              host='mysql-5632a4182a17-public.rds.volces.com',
                              port=3306,
                              database='etlctl')
with cnx.cursor() as cursor:
    cursor.execute(sql, (993,))
    one = cursor.fetchone()
    print(one)
cnx.close()


# import psycopg2
# pg_config = {
#     'host': '127.0.0.1',
#     'port': 5432,
#     'database': 'postgres',
#     'user': 'postgres',
#     'password': 'postgres'
# }
# cnx = psycopg2.connect(**pg_config)
# with cnx.cursor() as cursor:
#     cursor.execute("SELECT current_date")
#     one = cursor.fetchone()
#     print(one)
# cnx.close()

# 使用ssh隧道访问需要密钥登录的服务器
# from sshtunnel import SSHTunnelForwarder

# from pyhive import presto
# presto_config ={
#     "host":"172.16.60.9",
#     "port":"9000",
#     "username":"hive",
#     "schema":"ads",
#     "catalog":"hive"
# }
# with SSHTunnelForwarder(
#     ssh_address_or_host=('159.75.230.189', 22),
#     ssh_username="root",
#     ssh_pkey='D:\\工作\\QY_Test_BD1.pem',
#     remote_bind_address=('172.16.60.9', 9000),
#     # local_bind_address=('127.0.0.1', 5143)
# ) as server:
#     server.check_tunnels()
#     print(server.tunnel_is_up)
#     cnx = presto.connect(**presto_config)
#     cursor = cnx.cursor()
#     cursor.execute("select current_date")
#     one = cursor.fetchone()
#     print(one)
#     cursor.close()
#     cnx.close()


# 使用ssh隧道访问需要密钥登录的服务器
# from sshtunnel import SSHTunnelForwarder
# from pyhive import presto

# with SSHTunnelForwarder(
#     ssh_address_or_host=('118.145.151.90',22),
#     ssh_username="root",
#     ssh_password="0S^tNOHRgNMw",
#     # ssh_pkey='D:\\工作\\QY_Test_BD1.pem',
#     remote_bind_address=('192.168.60.7', 8084),
#     local_bind_address=('127.0.0.1', 8080)
# ) as server:
#     server.check_tunnels()
#     print(server.local_is_up(('192.168.60.7', 8084)))
#     # 连接数据库
#     presto_config ={
#     "host":"127.0.0.1",
#     "username":"biadmin",
#     "port":server.local_bind_port
#     }
#     # print(presto_config)
#     cnx = presto.connect(**presto_config)
#     cursor = cnx.cursor()
#     cursor.execute("select count(1) from dim.dim_xl_account")
#     one = cursor.fetchone()
#     print(one)
#     cursor.close()
#     cnx.close()
